#pragma once
#include <map>
#include <memory>
#include <string>
#include <list>
#include <vector>
#include <chrono>
#include <cJSON.h>
#include <format_interface.hh>
class network_load : public format_interface{
    public:
        explicit network_load(std::string ethernet_data_fileName = "/proc/net/dev", std::string eth_name = "enp42s0");
        bool is_device_up() const;
        std::string get_devicename();
        uint64_t get_rxBytes_persecond();
        uint64_t get_txBytes_persecond();

        virtual cJSON* to_json();
        virtual const char*  get_name();

        ~network_load();


    private:
        std::string ethernet_dataFile;
        std::string eth_dev;
        std::chrono::time_point<std::chrono::steady_clock> timeBefore;
        std::chrono::time_point<std::chrono::steady_clock> timeBefore_rx;
        std::chrono::time_point<std::chrono::steady_clock> timeBefore_tx;
        uint64_t BytesPerSecond = 0;
        std::chrono::time_point<std::chrono::steady_clock> timeStamp;
        std::map<std::string, std::string> networkstatMap;
        bool isDeviceAvailable = false;

        uint64_t m_totalTransceivedBytes = 0;
        uint64_t m_totalReceivedBytes = 0;
        uint64_t m_totalTransmittedBytes = 0;

    private:
        uint64_t parse_ethernet_device();
        void init_network_monitor() ;
        uint64_t get_TXBytes_sincestartup() ;
        uint64_t get_RXBytes_sinceStartup();
};